﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProgramCat
{
    static class Program
    {
        

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //regasm ProgramCatCom.exe /tlb:pcc.tlb
            RegisterDcomServer();
            Application.ApplicationExit += new EventHandler(Application_ApplicationExit);

            Application.Run(new Form1());
        }
        static void Application_ApplicationExit(object sender, EventArgs e)
        {
            RevokeDcomServer();
        }
        static uint m_ComCookie = 0;

        private static void RegisterDcomServer()
        {
            int hr = ComHelperClass.CoRegisterClassObject(
                ComHelperClass.CLSID_ComClass,
                new ComClassFactory(),
                ComHelperClass.CLSCTX_LOCAL_SERVER,
                ComHelperClass.REGCLS_MULTIPLEUSE,
                out m_ComCookie);
            if (hr != 0)
                Marshal.ThrowExceptionForHR(hr);
        }
        private static void RevokeDcomServer()
        {
            if (m_ComCookie != 0)
                ComHelperClass.CoRevokeClassObject(m_ComCookie);

        }
    }
}
